
# delim ;  

****************************************;	
*-This program is used to add a row indicating the use of sample id when using areg;
cap program drop add_lab_FE;
program define add_lab_FE;
	matrix V = [vecdiag(e(V)),1];
	matrix V=diag(V);
	matrix b=[e(b),1];
	matrix colnames b= `:  colnames e(b)' `1';
	matrix colnames V= `:  colnames e(V)' `1';
	erepost b=b V=V	,rename;
end;
****************************************;	
*-This program calculates summary stats for regression tables;
cap program drop sum_stats;
program define sum_stats;
	sum Du_lane_miles_IH ;
	estadd  scalar mean_Du_lane_miles_IH =r(mean) ;
	sum exp_L_IH_SF12a_r ;
	estadd  scalar mean_exp_L_IH_SF12a_r=r(mean) ;
end;
****************************************;	
*-This program plots year dummies for slope of PPF against time;
cap program drop plot_dummies;
program define plot_dummies;
	*settings for plots;
	local pdf_plot_settings = 	"bgcolor(white) 
					graphregion(color(white)) plotregion(ls(none))  
					xmtick(1984(1)2008)  
					xlabel(1984(4)2008)
					ymtick(##5)
					scale(*1.5)  
					legend(off)";
	preserve;
	*save se to disk;
	mata: se=sqrt(diagonal(st_matrix("e(V)"))); // converts e(V) into se and placed in mata matrix se
	clear;
	getmata se, force ;
	gen counter=_n;
	save se,replace;
	
	*save coefficients to disk and organize;
	mat beta=e(b);
	mat list beta;
	clear;
	set obs 1;
	display"1";
	svmat double beta;
	*file in memory is a single row year effects from regression;
	gen dummy=1;
	display"1";
	reshape long beta,  i(dummy) j(year);
	gen counter=_n;
	*merge with se;
	merge 1:1 counter using se;
	drop if counter>25;
	drop _merge counter;
	*just keep year X expenditure coefficients;
	drop if year==.;
	replace year = year+1983;
	sort year;
	*file in memory gives bin, mean y and se;
	gen up5 = beta+1.96*se;
	gen down5 = beta-1.96*se;

	save beta, replace;
	*file in memory is a list of year by year inverse prices and CI's;


	twoway (rcap up5 down5 year, lstyle(ci)) (scatter beta year),`pdf_plot_settings' xtitle("") ; 
	graph export "temp_t.pdf", replace;
	erase se.dta;
	erase beta.dta;
	save "temp_betas.dta", replace;
	restore;
end;
****************************************;	
*-This program plots year dummies for DL vs expenditure;
cap program drop plot_DLdummies ;
program define plot_DLdummies;
	*settings for plots;
	local pdf_plot_settings = 	"bgcolor(white) 
					graphregion(color(white)) plotregion(ls(none))  
					xmtick(1980(1)2008)  
					xlabel(1980(10)2010)
					ymtick(##5)
					scale(*1.5)  
					legend(off)";
	preserve;
	*save se to disk;
	mata: se=sqrt(diagonal(st_matrix("e(V)"))); // converts e(V) into se and placed in mata matrix se
	clear;
	getmata se, force ;
	gen counter=_n;
	save se,replace;
	
	*save coefficients to disk and organize;
	mat beta=e(b);
	mat list beta;
	clear;
	set obs 1;
	svmat double beta;
	*file in memory is a single row year effects from regression;
	gen dummy=1;
	reshape long beta,  i(dummy) j(exp);
	gen counter=_n;
	*merge with se;
	merge 1:1 counter using se;
	drop if counter>7;
	drop _merge counter;
	
	*just keep year X expenditure coefficients;
	drop if exp==.;
	replace exp = exp*100-50;
	sort exp;
	*file in memory gives bin, mean y and se;
	gen up5 = beta+1.96*se;
	gen down5 = beta-1.96*se;

	save beta, replace;
	*file in memory is a list of year by year inverse prices and CI's;


	twoway (rcap up5 down5 exp, lstyle(ci)) (scatter beta exp), xtitle("") `pdf_plot_settings'; 
	graph export "temp_t.pdf", replace;
	erase se.dta;
	erase beta.dta;

	restore;
end;
****************************************;	
